package jbpm.example.preciouscode;

import com.google.inject.AbstractModule;
import com.google.inject.jndi.JndiIntegration;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;

/**
 * User: goettl
 * Date: 16.02.11
 * Time: 21:54
 */
public class GuiceConfigJNDI extends AbstractModule {

    @Override
    protected void configure() {
        // bind(Registration.class).to(RegistrationImpl.class);
        try {
            Properties properties = new Properties();
            properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
            properties.put("java.naming.provider.url", "jnp://localhost:1099");
            properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
            bind(Context.class).toInstance(new InitialContext(properties));
        } catch (NamingException e) {
            e.printStackTrace();
        }
        bind(Registration.class).toProvider(JndiIntegration.fromJndi(Registration.class, "java:/register/RegistrationBean/remote"));
    }
}
